#include "USBCdc.h"
#include "GQueue.h"
#include "rtthread.h"
#include "tusb.h"
#include "main.h"

#define CDC_ITF                 0

uint16_t CDC_Send(void const* buf,uint32_t bs)
{
    uint32_t sendLen = 0;
    // 某些情况下这个判断不准确
//    if(!tud_ready())
//    {
//        return 0;
//    }
    uint32_t bufferRemaining = tud_cdc_n_write_available(CDC_ITF);
    sendLen = bs > bufferRemaining ? bufferRemaining: bs;

    uint32_t cdc_sent = tud_cdc_n_write(CDC_ITF,buf,sendLen);

    tud_cdc_n_write_flush(CDC_ITF);

    return cdc_sent;
}



